// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: PpfExits.java 75 2005-08-02 16:04:05Z richetl $	
//

import java.util.*;
import java.io.*;

class PpfExits
{
    class Exit
    {
	private String name;
	public String getName() {
	    return name;
	}
	public void setName(String n) {
	    name = n;
	}
	public void print(PrintStream file) {
	    if(!name.equals("drop")) {
		file.println("\tvoid " + name + "(lee::PktData * pkt) {");
		file.println("\t\tlee::FuncExit * ex = new lee::FuncExit();");
		file.println("\t\tex->exit = " + name.toUpperCase() + ";");
		file.println("\t\tex->pkt = pkt;");
		file.println("\t\texitList->push_back(ex);");
		file.println("\t}");
	    }
	}
	public void printPubs(PrintStream file, int index) {
	    file.println("\tstatic const int " + name.toUpperCase() + 
			 " = " + index + ";");
	}
    }

    private LinkedList exitList;

    public PpfExits() {
	exitList = new LinkedList();
    }

    public void print(PrintStream file) {
	Iterator exits = exitList.iterator();
	int listSize = exitList.size();
	file.println();
	for(int i = 0; i < listSize; i++) {
	    Exit exit = (Exit)exits.next();
	    exit.print(file);
	}
    }

    public void printPubs(PrintStream file) {
	Iterator exits = exitList.iterator();
	int listSize = exitList.size();
	file.println();
	for(int i = 0; i < listSize; i++) {
	    Exit exit = (Exit)exits.next();
	    exit.printPubs(file, i);
	}
    }

    public void addExit(Exit e) {
	exitList.addLast(e);
    }
}

